package com.ww.springboot.boot.baseTest.队列;

import com.google.common.collect.Queues;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2024-07-09 09:41
 */
public class QueueTest {

    public static void main(String[] args) throws InterruptedException {

        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(100,true);

        new Thread(()->{
            for (int i = 0; i < 1000000; i++) {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                blockingQueue.add(String.valueOf(i));
            }

        }).start();

        while (true){
            List<String> pkgCodes = new ArrayList<>();
            Queues.drain(blockingQueue, pkgCodes, 10, 200, TimeUnit.MILLISECONDS);
            System.out.println(pkgCodes.size());
        }



    }
}
